package com.cskaoyan.market.admin.controller;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.cskaoyan.market.admin.service.MarketAdminDashboardService;
import com.cskaoyan.market.admin.service.impl.MarketAdminDashboardServiceImpl;
import com.cskaoyan.market.util.JacksonUtil;
import com.cskaoyan.market.util.ResponseUtil;

/**
 * 首页仪表盘数据
 *
 * @author BlackFlame33
 * @date 2023/03/19
 **/
@WebServlet("/admin/dashboard")
public class AdminDashboardController extends HttpServlet {
    private MarketAdminDashboardService marketAdminDashboardService = new MarketAdminDashboardServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Map<String, Integer> data = new HashMap<>();
        // 查询商品信息总数
        Integer goodsTotal = marketAdminDashboardService.getGoodsTotal();
        data.put("goodsTotal", goodsTotal);
        // 查询用户总数
        Integer userTotal = marketAdminDashboardService.getUserTotal();
        data.put("userTotal", userTotal);
        // 查询商品货品总数
        Integer productTotal = marketAdminDashboardService.getProductTotal();
        data.put("productTotal", productTotal);
        // 查询订单总数
        Integer orderTotal = marketAdminDashboardService.getOrderTotal();
        data.put("orderTotal", orderTotal);
        Object ok = ResponseUtil.ok(data);
        resp.getWriter().println(JacksonUtil.writeValueAsString(ok));
    }
}